<@sp.pagehead shiroUserHelper.getCurrentShiroUser().parentSources />
<div class="panel panel-inverse" data-sortable-id="form-validation-1">
    <div class="panel-heading">
        <h4 class="panel-title">菜单表单</h4>
    </div>
    <div class="panel-body">
        <form id="sourceEditForm" name="sourceEditForm" action="" method="post" class="form-horizontal form-bordered">
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3">菜单名称</label>
                <div class="col-md-7 col-sm-7">
                    <input type="text" id="name" class="form-control" name="name" placeholder="菜单名称 2-10位"
                           value="${tSource.name}"
                           rangelength="2,10" required/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3">菜单地址</label>
                <div class="col-md-7 col-sm-7">
                    <input type="text" id="sourceCode" class="form-control" name="sourceCode"
                           placeholder="菜单地址 6-50位" rangelength="6,50" required value="${tSource.sourceCode}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3">菜单排序</label>
                <div class="col-md-7 col-sm-7">
                    <input type="text" id="style" class="form-control" name="style" placeholder="菜单排序,数字类型"
                           required value="${tSource.style}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3">是否菜单</label>
                <div class="col-md-7 col-sm-7">
                    <select class="form-control" name="isMenu" id="isMenu" required>
                        <option value="">--请选择--</option>
                        <option
                        <#if tSource.isMenu == 0> selected</#if> value="0">否</option>
                    <option
                    <#if tSource.isMenu == 1> selected
                </#if> value="1">是</option>
                </select>
            </div>
    </div>
    <div class="form-group">
        <label class="control-label col-md-3 col-sm-3">是否日志</label>
        <div class="col-md-7 col-sm-7">
            <select class="form-control" name="isLog" id="isLog" required>
                <option value="">--请选择--</option>
                <option
                <#if tSource.isLog == 0> selected</#if> value="0">否</option>
            <option
            <#if tSource.isLog == 1> selected
        </#if> value="1">是</option>
        </select>
    </div>
</div>
<div class="form-group">
    <label class="control-label col-md-3 col-sm-3">菜单状态</label>
    <div class="col-md-7 col-sm-7">
        <select class="form-control" name="status" id="status" required>
            <option value="">--请选择--</option>
            <option
            <#if tSource.status == 'A'> selected</#if> value="A">有效</option>
        <option
        <#if tSource.status == 'D'> selected
    </#if> value="D">无效</option>
    </select>
</div>
</div>
<div class="form-group">
    <label class="control-label col-md-3 col-sm-3">菜单描述</label>
    <div class="col-md-7 col-sm-7">
                    <textarea class="form-control" placeholder="请填写菜单描述.... 1-100位" rows="5" name="description"
                              rangelength="1,100">${tSource.description}</textarea>
    </div>
</div>
<div class="form-group">
    <label class="control-label col-md-3 col-sm-3">上级菜单</label>
    <div class="col-md-7 col-sm-7">
        <select class="form-control" name="parentCode" id="parentCode">
            <option value="">---请选择---</option>
            <#if sourceTree?has_content && sourceTree?exists>
            <#list sourceTree as st>
            <option value="${st.id}"
            <#if tSource.parent.id == st.id> selected</#if>>${st.name}</option>
    </#list>
</#if>
</select>
</div>
</div>
<div class="form-group">
    <label class="control-label col-md-3 col-sm-3">图标样式</label>
    <div class="col-md-7 col-sm-7">
        <input type="text" id="icon" class="form-control" name="icon" value="${tSource.icon}" placeholder="菜单图标"/>
    </div>
</div>
<div class="form-group">
    <label class="control-label col-md-3 col-sm-3"></label>
    <div class="col-md-7 col-sm-7">
        <button type="button" id="sourceEditSubmitButton" class="btn btn-sm btn-success">提交</button>
        <button type="button" class="btn btn-sm btn-default"
                onclick="getData('${rc.contextPath}/source/query','${shiroUserHelper.getCurrentShiroUser().parentMenuSource.name}')">
            返回
        </button>
    </div>
</div>
</form>
</div>
<script type="application/javascript">

    $(function () {

        $('#sourceEditSubmitButton').click(function () {
            $('#sourceEditForm').submit();
        })

        $('#sourceEditForm').validate({
            rules: {
                style: {
                    isNumber: true
                },
                parentCode: {
                    isNumber: true
                }
            },
            messages: {
                style: {
                    isNumber: "请输入数字"
                },
                parentCode: {
                    isNumber: "请输入数字"
                }
            },
            errorPlacement: function (error, element) {
                error.appendTo(element.parent());
            },
            submitHandler: function () {
                postDataByForm('${rc.contextPath}/source/edit/${tSource.id}', '${shiroUserHelper.getCurrentShiroUser().parentMenuSource.name}', 'sourceEditForm');
            }
        })
    })
</script>